package vin.servlet.study;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class ServletDemo11
 */
public class ServletDemo11 extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ServletDemo11() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ServletContext context=this.getServletContext();  
        
	    InputStream in=context.getResourceAsStream("/bbb.text");  
	    BufferedReader br=new BufferedReader(new InputStreamReader(in));  
	     
	    String line= br.readLine();  
	     
	    response.getWriter().write(line);  
		// TODO Auto-generated method stub
		//response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}
	
	@Override  
	  
	//复写了service中的getLastModified()方法  
	protected long getLastModified(HttpServletRequest req) {  
	   //获取文件  
	   ServletContext context=this.getServletContext();  
	   String path = context.getRealPath("/bbb.text");  
	   File file=new File(path);  
	   return file.lastModified();  
	} 

}
